package com.wealth.scsj.b_app.view.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.vondear.rxtools.RxTool;
import com.wealth.scsj.b_app.R;
import com.wealth.scsj.b_app.base.MyWalletBalanceBase;
import com.wealth.scsj.b_app.base.SettleAmountSumForDeliveryBase;
import com.wealth.scsj.b_app.bean.MyWalletBalanceBean;
import com.wealth.scsj.b_app.bean.SettleAmountSumForDeliveryBean;
import com.wealth.scsj.b_app.presenter.GetMyWalletBalancePresenter;
import com.wealth.scsj.b_app.presenter.SettleAmountSumForDeliveryPresenter;
import com.wealth.scsj.b_app.utils.SkipUtils;

import okhttp3.RequestBody;


/**
 * 我的钱包首页
 */
public class MyWalletActivity extends BaseActivity implements View.OnClickListener,SettleAmountSumForDeliveryBase.IView
    ,MyWalletBalanceBase.IView{

    private TextView mMoneyTv;
    private RelativeLayout mMyRechargeRl;
    private RelativeLayout mMyWithdrawRl;
    /**
     * 解绑银行卡
     */
    private TextView mBankCardStateTv;
    private RelativeLayout mMyBankCard;
    private RelativeLayout mMoneyDetailLay;
    private RelativeLayout mMyShareprofit;
    /**
     * 修改
     */
    private TextView mPayPswStateTv;
    private RelativeLayout mMyPasswordLay;
    /**
     * 未认证
     */
    private TextView mAuthenticationStateTv;
    private RelativeLayout mRealNameAuthenticationRl;
    private RelativeLayout mMain;

    SettleAmountSumForDeliveryPresenter  mSettleAmountSumPresenter;
    GetMyWalletBalancePresenter mBalancePresenter;
    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_my_wallet);
//        ScreenAdapterTools.getInstance().loadView((ViewGroup) getWindow().getDecorView());
        //ScreenAdapterTools.getInstance().reset(this);//如果希望android7.0分屏也适配的话,加上这句

        initToolbar();
        setToolbarTitle("财务对账");
        hasBack(true);
        initView();
        JSONObject object = new JSONObject();

        mSettleAmountSumPresenter =new SettleAmountSumForDeliveryPresenter(this);
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),object.toString());
        mSettleAmountSumPresenter.deliverData(body);

        mBalancePresenter =new GetMyWalletBalancePresenter(this);
        RequestBody body1 = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),object.toString());
        mBalancePresenter.deliverData(body1);
    }

    @Override
    protected void initView() {

        mMoneyTv = (TextView) findViewById(R.id.money_tv);
        mMyRechargeRl = (RelativeLayout) findViewById(R.id.my_recharge_rl);
        mMyRechargeRl.setOnClickListener(this);
        mMyWithdrawRl = (RelativeLayout) findViewById(R.id.my_withdraw_rl);
        mMyWithdrawRl.setOnClickListener(this);
        mBankCardStateTv = (TextView) findViewById(R.id.bank_card_state_tv);
        mMyBankCard = (RelativeLayout) findViewById(R.id.my_bank_card);
        mMyBankCard.setOnClickListener(this);
        mMoneyDetailLay = (RelativeLayout) findViewById(R.id.money_detail_Lay);
        mMoneyDetailLay.setOnClickListener(this);
        mMyShareprofit = (RelativeLayout) findViewById(R.id.my_shareprofit);
        mMyShareprofit.setOnClickListener(this);
        mPayPswStateTv = (TextView) findViewById(R.id.pay_psw_state_tv);
        mMyPasswordLay = (RelativeLayout) findViewById(R.id.my_password_Lay);
        mMyPasswordLay.setOnClickListener(this);
        mMain = (RelativeLayout) findViewById(R.id.main);

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        if(RxTool.isFastClick(3000)){
            switch (v.getId()) {
                case R.id.my_bank_card://预计收益
                    SkipUtils.toIncomPage(MyWalletActivity.this);
                    break;
                case R.id.money_detail_Lay: //订单明细
                    SkipUtils.toOrderDetail(MyWalletActivity.this);
                    break;
                case R.id.my_shareprofit://账单记录
                    SkipUtils.toWithdrawalRecordPage(MyWalletActivity.this);
                    break;
                case R.id.my_password_Lay://支付设置
//                SkipUtils.toPaymentSettings(this);
//                SkipUtils.toWithdrawalRecordPage(MyWalletActivity.this);
                    SkipUtils.toPaymentSettingsPage(MyWalletActivity.this);

                    break;
                case R.id.my_recharge_rl:
                    SkipUtils.toAddBankCard(this);
                    break;
                case R.id.my_withdraw_rl://我要提现
                    SkipUtils.toCashBalabce(this);
                    break;

            }
        }
    }

    /**
     * 预期收益接口回调
     * @param s
     * @param bean
     */
    @Override
    public void showSuccessMsg(String s, SettleAmountSumForDeliveryBean bean) {
        if(bean.getData()!=null){
            mBankCardStateTv.setText(bean.getData());
        }else{
            mBankCardStateTv.setText("0");
        }
    }

    /**
     * 可提现金额接口回调
     * @param s
     * @param bean
     */
    @Override
    public void showSuccessMsg(String s, MyWalletBalanceBean bean) {
        if(bean.isSuccess()){
            if(bean.getData()!=null){
                mMoneyTv.setText(bean.getData());
            }else{
                mMoneyTv.setText("0");
            }
        }
    }

    @Override
    public void showErrorMsg(String s) {

    }
}
